package com.tripwego.client.ui.widget.activite;

import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.tripwego.client.model.ActiviteModel;
import com.tripwego.client.ui.widget.FlexTableHelper;

public class LodgingCheckinWidget extends LodgingWidget {

	/*
	 * Elements graphiques
	 */
	private final HTML html_title = new HTML("Name - Type - Arriv\u00E9e");

	private final HTML html_detail = new HTML("Arriv\u00E9e\r\n<br>D\u00E9part\r\n<br>Nuits", true);

	/**
	 * 
	 */
	public LodgingCheckinWidget(ActiviteModel activiteModel) {
		super(activiteModel);

		viewPanel.setStyleName("LodgingCheckinWidget");
		viewPanel.setSize("350px", "");

		Image image_icon = new Image(activiteModel.getIconUrl());
		viewPanel.setWidget(0, 0, image_icon);
		viewPanel.getCellFormatter().setWidth(0, 0, "1%");
		image_icon.setSize("24px", "24px");

		viewPanel.setWidget(0, 1, html_title);
		viewPanel.getCellFormatter().setWidth(0, 1, "100%");
		panel_actions.setStyleName("horizontalPanel_actions");
		panel_actions.setSpacing(2);

		viewPanel.setWidget(0, 2, panel_actions);
		panel_actions.setWidth("1%");

		panel_actions.add(image_step);
		image_step.setTitle("Point d'arr\u00EAt sur la carte");

		panel_actions.add(image_update);
		image_update.setTitle("Modifier l'activit\u00E9");
		panel_actions.add(image_delete);

		image_delete.setTitle("Supprimer l'activit\u00E9");
		viewPanel.getCellFormatter().setVerticalAlignment(0, 2, HasVerticalAlignment.ALIGN_TOP);
		viewPanel.getCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_RIGHT);

		viewPanel.setWidget(1, 1, html_detail);
		viewPanel.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
		viewPanel.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
		viewPanel.getFlexCellFormatter().setRowSpan(0, 0, 2);
		viewPanel.getFlexCellFormatter().setRowSpan(0, 2, 2);
		FlexTableHelper.fixRowSpan(viewPanel);
		viewPanel.getFlexCellFormatter().setRowSpan(0, 0, 2);

		String title = activiteModel.getNom().concat(" - Checkin");
		html_title.setHTML("<b>".concat(title).concat("</b>"));

		DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("EEE, MMM d");

		StringBuilder sb_detail = new StringBuilder();
		sb_detail.append("Arrivee : ").append(dateTimeFormat.format(activiteModel.getDateDeb()));
		sb_detail.append("<br>Depart : ").append(dateTimeFormat.format(activiteModel.getDateFin()));
		sb_detail.append("<br>").append(activiteModel.getNbDay()).append(" nuit(s)");

		html_detail.setHTML(sb_detail.toString());
	}
}
